#ifndef MSGSENDER_H
#define MSGSENDER_H

#include <QTcpSocket>
#include "protocol.h"

class MsgSender : public QObject
{
    Q_OBJECT
public:
    explicit MsgSender(QObject *parent = 0);

signals:
    void connected();
    void errorString(const QString& sError);
    void showResponse(RESTYPE resType);
    void showVehInfo(VEHICLE* vehQueue);
    void showHeadVeh(const VEHICLE& headVeh);
public slots:
    void slot_connected();
    void slot_errorString();
    void readData();
    //处理回应报文
    void handleResponse(SResponse& response);
    //处理队列报文
    void handleVehQueue(SVehInfo& vehInfo);
    //处理队首报文
    void handleHeadVeh(SHEADVEH &headVeh);
    //异或校验
    bool isVaild(void * buffer, size_t nSize, quint8 nXor);
    //操作队列
    void modifyVehQueue(PACKETTYPE nType, int nClass);
public:
    void connectToHost(const QString& sIp, int nPort);
private:
    QTcpSocket m_socket;
    QByteArray m_data;

};
quint8 getXor(const char* buffer, int nSize);
#endif // MSGSENDER_H
